SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.vwrAlumnodivision
AS
SELECT     dbo.tb_AlumnoDivision.idRelDivisionAlumno AS ID, dbo.tb_Divisionestemp.Mnemo, dbo.tb_AlumnoDivision.AnioLectivo, 
                      dbo.tb_AlumnoDivision.Desde, dbo.tb_AlumnoDivision.Hasta, dbo.tb_Pases.OrganizacionDestino, dbo.tb_AlumnoDivision.InscripcionDeOrigen, 
                      dbo.tb_AlumnoDivision.Baja, dbo.tb_CausaBajaAlumno.Descripcion AS Causa_Baja, dbo.tb_AlumnoDivision.Division, dbo.tb_Alumnos.Documento, 
                      dbo.tb_AlumnoDivision.Alumno, dbo.tb_Alumnos.Apellidos + dbo.tb_Alumnos.Nombres AS Descripcion
FROM         dbo.tb_AlumnoDivision INNER JOIN
                      dbo.tb_Divisionestemp ON dbo.tb_AlumnoDivision.Division = dbo.tb_Divisionestemp.idDivision INNER JOIN
                      dbo.tb_Alumnos ON dbo.tb_AlumnoDivision.Alumno = dbo.tb_Alumnos.idAlumno LEFT OUTER JOIN
                      dbo.tb_Inscripciones ON dbo.tb_AlumnoDivision.InscripcionDeOrigen = dbo.tb_Inscripciones.idInscripcion LEFT OUTER JOIN
                      dbo.tb_Pases ON dbo.tb_AlumnoDivision.PaseDeOrigen = dbo.tb_Pases.idPase LEFT OUTER JOIN
                      dbo.tb_CausaBajaAlumno ON dbo.tb_AlumnoDivision.CausaBaja = dbo.tb_CausaBajaAlumno.IdCausa
where dbo.tb_AlumnoDivision.baja is null or dbo.tb_AlumnoDivision.baja = 'n'


GO
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [Alumnos]
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [CertificacionesServicios]
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [Coordinaciones]
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [GestionInstitucional]
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [Informatica]
GRANT SELECT ON  [dbo].[vwrAlumnodivision] TO [SoloVer]
GO
